package assignment1;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 
 * @author Kha Nguyen - 598240
 *
 */
public class CountWordTask implements Runnable {
    private final List<String> tokensToScan;

    private final Map<String, Integer> wordCount = new HashMap<String, Integer>();

    public CountWordTask(List<String> tokensToScan, Set<String> tokens) {
        super();
        this.tokensToScan = tokensToScan;
        for (String token : tokens) {
            wordCount.put(token, 0);
        }
    }

    public Map<String, Integer> getWordCount() {
        return wordCount;
    }

    @Override
    public void run() {
        final long start = System.currentTimeMillis();
        for (String token : tokensToScan) {
            if (wordCount.containsKey(token)) {
                int currentCount = wordCount.get(token);
                wordCount.put(token, ++currentCount);
            }
        }
        System.out.println("Count: " + (System.currentTimeMillis() - start));
    }

}
